<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
import {optionsAction} from '@/api/statistics'
export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '350px'
    },
    autoResize: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      chart: null
    }
  },
  watch: {
  },
  mounted() {
    this.$nextTick(() => {
      this.initData()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initData(){
      optionsAction("exWarehouse").then(response=>{
        this.datas =  response.data;
      }).finally(()=>{
         this.initChart()
      })
    },
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.setOptions()
    },
    setOptions({ expectedData, actualData } = {}) {
      this.chart.setOption({
        color:['#73c0de','#9a60b4','#5470c6','#ee6666','#3ba272','#91cc75', '#fac858', '#fc8452', '#ea7ccc'],
        xAxis: {
          // data: ["沙县区","清流县","永安市","宁化县","大田县","沙县区","市管理中心"],
          data:this.datas.xData
          // boundaryGap: false,
          // axisTick: {
          //   show: false
          // }
        },
        grid: {
          left: '1%',
          right: '3%',
          bottom: '2%',
          containLabel: true
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            crossStyle: {
              color: '#999'
            }
          }
        },
        yAxis: {
          axisTick: {
            show: false
          }
        },
        legend: {
          data: ['移交出库', '调用出库', '处置出库']
        },
        series: [{
          name: '移交出库',
          // smooth: true,
          type: 'bar',
          // data: [120, 200, 150, 80, 70, 110, 130],
          data:this.datas.yData.innums,
          animationDuration: 2800,
          animationEasing: 'cubicInOut'
        },
        {
          name: '调用出库',
          // smooth: true,
          type: 'bar',
          // data: [80, 120, 70, 10, 20, 40, 60],
          data:this.datas.yData.deals,
          animationDuration: 2800,
          animationEasing: 'quadraticOut'
        },
        {
          name: '处置出库',
          // smooth: true,
          type: 'line',
          // data: [180, 220, 170, 110, 120, 140, 160],
          data:this.datas.yData.outnums,
          animationDuration: 2800,
          animationEasing: 'quadraticOut'
        }]
      })
    }
  }
}
</script>
